package com.totoro.mybatis.mul_datasource.config;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.util.Queue;

/**
 * Created by Niki on 2018/8/15 11:51
 */
@Configuration
public class DataSourceConfig {

    @Bean(name = "db1")
    @ConfigurationProperties(prefix = "spring.datasource.db1")
    public DataSource dataSource() {
        return DataSourceBuilder.create().type(MysqlDataSource.class).build();
//                .type(MysqlDataSource.class)
//                .url("jdbc:mysql://127.0.0.1:3306/test?characterEncoding=UTF-8")
//                .username("root")
//                .password("root123456")
//                .build();
    }

    @Bean(name = "db2")
    @ConfigurationProperties(prefix = "spring.datasource.db2")
    public DataSource dataSource2() {
        return DataSourceBuilder.create().type(MysqlDataSource.class).build();
//                .url("jdbc:mysql://127.0.0.1:3306/school?characterEncoding=UTF-8")
//                .username("root")
//                .password("root123456")
//                .build();
    }
}
